import { get, post } from '../../../utils/request.js'
import global from '../../../utils/global.js'
var WxParse = require('../../../wxParse/wxParse.js');
let that
Page({

  data: {

  },

  onLoad: function (options) {
    that = this
    that.setData({
      productId: options.productId,
      userId: wx.getStorageSync("useInfo").id
    })
    setTimeout(function () {
      that.setData({
        userId: wx.getStorageSync("useInfo").id
      })
    }, 1000)
  },
  onShow:function(){
    that.getProductDetail(that.data.productId)
    console.log(wx.getStorageSync("useInfo"))
    that.setData({
      userId: wx.getStorageSync("useInfo").id
    })
  },
  getProductDetail: (id) => {
    post(global.apiUrl.productDetail, { productId: id }, (res) => {
      WxParse.wxParse('article', 'html', res.obj.product.detail, that, 5)
      that.setData({
        productDetail:res.obj
      })
    })
  },
  // 去预约
  postAppointment:function(e){
    console.log(e)
    if (!that.data.userId){
      wx.showToast({
        title: '预约加载中',
        icon: 'loading',
        duration: 2000,
        mask: true
      })
      that.setData({
        userId: wx.getStorageSync("useInfo").id
      })
    }
      wx.navigateTo({
        url: '../postAppointment/postAppointment?productId=' + e.currentTarget.dataset.id + '&userId=' + that.data.userId,
      })
    // setTimeout(function () {
    //   wx.navigateTo({
    //     url: '../postAppointment/postAppointment?productId=' + e.currentTarget.dataset.id + '&userId=' + that.data.userId,
    //   })
    // }, 2000)
    
  }
})